package com.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
@CrossOrigin(origins = "*") // 允许所有跨域请求
public class LoginController {

    @PostMapping("/login")
    public ResponseEntity<?> login(@RequestBody LoginRequest loginRequest) {
        // 简单验证示例，实际应使用数据库验证
        if ("admin".equals(loginRequest.getUsername())
                && "admin123".equals(loginRequest.getPassword())) {
            return ResponseEntity.ok().body("登录成功");
        }
        return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("无效的凭证");
    }

    public static class LoginRequest {
        private String username;
        private String password;

        // Getter和Setter
        public String getUsername() { return username; }
        public void setUsername(String username) { this.username = username; }
        public String getPassword() { return password; }
        public void setPassword(String password) { this.password = password; }
    }
}